﻿using System.ComponentModel;
using System.Drawing;
using System.Runtime.Versioning;
using System.Windows.Forms;

namespace zykControl
{
    [DesignTimeVisible(false)]
    [ToolboxItem(false)]
    public partial class ZykHFGridColumn
    {
        public ZykHFGridColumn()
        {
            InitializeComponent();
        }

        public event WidthChangedEventHandler? WidthChanged;

        public delegate void WidthChangedEventHandler();

        public string Title
        {
            get
            {
                return Label1.Text;
            }

            set
            {
                Label1.Text = value;
            }
        }

        private bool mIsMove;

        private void Splitter1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
                return;
            Width += e.X;
            mIsMove = true;
        }

        private void Splitter1_MouseUp(object sender, MouseEventArgs e)
        {
            if (mIsMove == true)
            {
                mIsMove = false;
                WidthChanged?.Invoke();
            }
        }

        private bool mIsBill;

        public bool IsBill
        {
            get
            {
                return mIsBill;
            }

            set
            {
                mIsBill = value;
                WidthChanged?.Invoke();
            }
        }

        private bool mIsDisplay;

        public bool IsDisplay
        {
            get
            {
                return mIsDisplay;
            }

            set
            {
                mIsDisplay = value;
            }
        }

        private int mIndex;

        /// <summary>
        /// 返回控件在容器中的索引
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        public int Index
        {
            get
            {
                return mIndex;
            }
        }

        internal void SetIndex(int theIndex)
        {
            mIndex = theIndex;
        }

        private int mColLeft;

        public int ColumnLeft
        {
            get
            {
                return mColLeft;
            }
        }

        internal void SetColumnLeft(int theColumnLeft)
        {
            mColLeft = theColumnLeft;
        }

        public ContentAlignment TextAlign
        {
            get
            {
                return Label1.TextAlign;
            }

            set
            {
                Label1.TextAlign = value;
            }
        }

        /// <summary>
        /// 返回/设置项的文本对齐方式
        /// </summary>
        /// <remarks></remarks>
        [SupportedOSPlatform("windows")] 
        public readonly StringFormat ItemFormat = new(StringFormatFlags.NoWrap);

        /// <summary>
        /// 返回/设置项的文本对齐方式
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        [SupportedOSPlatform("windows")]
        public ContentAlignment ItemAlign
        {
            get
            {
                var dAlign = default(ContentAlignment);
                switch (ItemFormat.Alignment)
                {
                    case StringAlignment.Near:
                        {
                            dAlign = ContentAlignment.TopLeft;
                            break;
                        }

                    case StringAlignment.Center:
                        {
                            dAlign = ContentAlignment.TopCenter;
                            break;
                        }

                    case StringAlignment.Far:
                        {
                            dAlign = ContentAlignment.TopRight;
                            break;
                        }
                }

                switch (ItemFormat.LineAlignment)
                {
                    case StringAlignment.Near:
                        {
                            break;
                        }

                    case StringAlignment.Center:
                        {
                            dAlign = (ContentAlignment)((int)dAlign * 16);
                            break;
                        }

                    case var @case when @case == StringAlignment.Near:
                        {
                            dAlign = (ContentAlignment)((int)dAlign * 256);
                            break;
                        }
                }

                return dAlign;
            }

            set
            {
                switch (value)
                {
                    case ContentAlignment.BottomLeft:
                    case ContentAlignment.MiddleLeft:
                    case ContentAlignment.TopLeft:
                        {
                            ItemFormat.Alignment = StringAlignment.Near;
                            break;
                        }

                    case ContentAlignment.BottomCenter:
                    case ContentAlignment.MiddleCenter:
                    case ContentAlignment.TopCenter:
                        {
                            ItemFormat.Alignment = StringAlignment.Center;
                            break;
                        }

                    default:
                        {
                            ItemFormat.Alignment = StringAlignment.Far;
                            break;
                        }
                }

                switch (value)
                {
                    case ContentAlignment.BottomCenter:
                    case ContentAlignment.BottomLeft:
                    case ContentAlignment.BottomRight:
                        {
                            ItemFormat.LineAlignment = StringAlignment.Far;
                            break;
                        }

                    case ContentAlignment.MiddleCenter:
                    case ContentAlignment.MiddleLeft:
                    case ContentAlignment.MiddleRight:
                        {
                            ItemFormat.LineAlignment = StringAlignment.Center;
                            break;
                        }

                    case ContentAlignment.TopCenter:
                    case ContentAlignment.TopLeft:
                    case ContentAlignment.TopRight:
                        {
                            ItemFormat.LineAlignment = StringAlignment.Near;
                            break;
                        }
                }

                TextAlign = value;
            }
        }
    }
}